# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/defconfig
# Maintainer: Jianhua Lu <lujianhua000@gmail.com>

_flavor="postmarketos-qcom-sm8250"
pkgname=linux-$_flavor
pkgver=6.13.0
pkgrel=0
pkgdesc="Mainline kernel fork for SM8250"
arch="aarch64"
_carch="arm64"
url="https://gitlab.postmarketos.org/jianhua/sm8250-mainline"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-nftables
	pmb:kconfigcheck-community
"
makedepends="
	bash
	bison
	findutils
	flex
	openssl-dev
	perl
	postmarketos-installkernel
	python3
"

# Source
_tag="sm8250-$pkgver"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_tag.tar.gz::https://gitlab.postmarketos.org/jianhua/sm8250-mainline/-/archive/$_tag/sm8250-mainline-$_tag.tar.gz
	$_config
"
builddir="$srcdir/sm8250-mainline-$_tag"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$arch" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	mkdir -p "$pkgdir"/boot

	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot/ \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir/boot/dtbs"
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
9d67f82cacbed9b1eb6663d848051de0abdfa5f763097203c6ef93ad157ab7bf0268e9dabbc4933bea75a9cb55905797ff83d91d78090c57abba2c3b500fcd5e  linux-postmarketos-qcom-sm8250-sm8250-6.13.0.tar.gz
5277ce718243dfd7ae7378d8c76777ef9d563974ecccf9fc1dad5d32f3f49930977cfd03176090e7dd0b74caf0bdbf665bea54595402b802c3eb7e658bd9a72b  config-postmarketos-qcom-sm8250.aarch64
"
